
var lotteryIdfd=""
var gamestares=sessionStorage.getItem("gamestare")
console.log(sessionStorage.getItem("gamestare"))
var getLotteryDrawDetail=""
var prizeListss=""
var text;
if(gamestares==0){
    //创建小游戏
    //渲染表格
    var coner=9//当前列表条数
    var listHtml=''
    for(var i=1; i<coner; i++){
        listHtml+=''
            +'<tr id="productList">'
            +'<td class="nus">'+Number(i)+'</td>'
            +'<td class="rfqg_td1">'
            +'<input type="button" id="setups'+i+'" class="btn  radius size-S"  onclick="setup('+i+')" value="设置"><span class="Prizenames" id="Prizename'+i+'"></span><br><span id="ids'+i+'" style="display: none">ID:<span class="youhuij" id="idcode'+i+'"></span></span><span style="display: none" class="amounts1" id="amounts'+i+'"></span><span style="display: none" class="" id="sendTotalNums'+i+'"></span><span style="display: none" class="useConditions1" id="useConditions'+i+'"></span>'
            +'</td>'
            +'<td class="rfqg_td2">'
            +'<input type="text" style="width: 107px;" oninput="checkMaxIut(this)" id="nameshow'+i+'" disabled="disabled" name="brandne2" class="input-text nameshows" value=""  autocomplete="off">'
            +'</td>'
            +'<td class="rfqg_td3">'
            +'<input type="text" style="width: 107px;" id="number'+i+'"  disabled="disabled" class="input-text numbers" onchange="numbers('+i+',this)" value="" name="brandne3"    autocomplete="off"  onkeyup="value=value.replace(/^(0+)|[^\\d]+/g,\'\')"  oninput = "value=value.replace(/[^\\d]/g,\'\')" maxlength="9">'
            +'</td>'
            +'<td class="rfqg_td4">'
            +'<span id="probability'+i+'"></span>'
            +'</td>'
            +'<td class="rfqg_td5">'
            +'<a id="edit'+i+'" style="color: #9c9c9c" onclick="edit('+i+')">编辑</a>'
            +'</td>'
            +'</tr>'
        $('#shunlist').html(listHtml)

    }
    //设置
    function setup(val) {
        sessionStorage.setItem("xuan",'123')
        sessionStorage.setItem("Serials",val)
        layer_show("添加奖品", "../promotion/setUp.html", "600", "300");
    }
}else {
    var lotteryIds=sessionStorage.getItem("viewdetail")
    //编辑小游戏
    $(function () {
        $.ajax({
            url: 'https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/getLotteryDrawDetail',
            cache: false, //禁用缓存
            dataType: "json",
            type:"post",
            async:false,//优先运行
            data:{
                "lotteryId":lotteryIds,
            },
            success: function (data) {
                if(data.data.lotteryDrawBase!=null){
                    var dataInter=data.data.lotteryDrawBase.rule;

                    ue.ready(function() {
                        ue.setContent(dataInter);
                    });

                    getLotteryDrawDetail=data.data.lotteryDrawBase
                    $("#lotteryAfterName").val(data.data.lotteryDrawBase.lotteryAfterName)
                    $("#lotteryBeforeName").val(data.data.lotteryDrawBase.lotteryBeforeName)
                    $("#logmin").val(data.data.lotteryDrawBase.startTime)
                    $("#logmax").val(data.data.lotteryDrawBase.endTime)
                    if(data.data.lotteryDrawBase.source.match('10')&&data.data.lotteryDrawBase.source.match('20')&&data.data.lotteryDrawBase.source.match('30')){
                        $(".paidTypes").prop("checked",true);
                    }else {
                        var groupCheckbox = data.data.lotteryDrawBase.source.split(",");
                        for (var i = 0; i < groupCheckbox.length; i++) {
                            if (groupCheckbox[i] == '10') {
                                $('#paidType1').prop("checked", true);
                            }
                            if (groupCheckbox[i] == '20') {
                                $('#paidType2').prop("checked", true);
                            }
                            if (groupCheckbox[i] == '30') {
                                $('#paidType3').prop("checked", true);
                            }
                        }
                    }

                    lotteryIdfd=data.data.lotteryDrawBase.lotteryId
                    $("#adPcUrl").val(data.data.lotteryDrawBase.pcUrl)
                    $("#adAppUrl").val(data.data.lotteryDrawBase.appUrl)
                    $("#adH5Url").val(data.data.lotteryDrawBase.h5Url)
                    //参加要求
                    if(data.data.lotteryDrawBase.joinRequire==10){
                        $("#joinRequire1").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                    }else  if(data.data.lotteryDrawBase.joinRequire==20){
                        $("#joinRequire2").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                    }else  if(data.data.lotteryDrawBase.joinRequire==30){
                        $("#joinRequire3").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                        $("#integrals").attr("disabled", "disabled");
                        $("#integral").css({
                            display: "inline"
                        });
                        $("#integrals").val(data.data.lotteryDrawBase.joinConsume)
                    }else  if(data.data.lotteryDrawBase.joinRequire==40){
                        $("#joinRequire4").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                        $("#ordershus").attr("disabled", "disabled");
                        $("#ordershu").css({
                            display: "inline"
                        });
                        $("#ordershus").val(data.data.lotteryDrawBase.joinConsume)
                        $("#fixeds").val("10000")
                        $("#fixeds").attr("disabled", "disabled")
                        $("#cycles").val("10000")
                        $("#cycles").attr("disabled", "disabled")
                    }else  if(data.data.lotteryDrawBase.joinRequire==50){
                        $("#joinRequire5").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                        $("#orderjins").attr("disabled", "disabled");
                        $("#orderjin").css({
                            display: "inline"
                        });
                        $("#orderjins").val(data.data.lotteryDrawBase.joinConsume)
                        $("#fixeds").val("10000")
                        $("#fixeds").attr("disabled", "disabled")
                        $("#cycles").val("10000")
                        $("#cycles").attr("disabled", "disabled")
                    }else  if(data.data.lotteryDrawBase.joinRequire==60) {
                        $("#joinRequire6").prop("checked", true);
                        $("#joinRequire1").attr("disabled", "disabled");
                        $("#joinRequire2").attr("disabled", "disabled");
                        $("#joinRequire3").attr("disabled", "disabled");
                        $("#joinRequire4").attr("disabled", "disabled");
                        $("#joinRequire5").attr("disabled", "disabled");
                        $("#joinRequire6").attr("disabled", "disabled");
                        $("#singleStrokes").attr("disabled", "disabled");
                        $("#singleStroke").css({
                            display: "inline"
                        });
                        $("#singleStrokes").val(data.data.lotteryDrawBase.joinConsume)
                    }
                    //抽奖方式

                    if(data.data.lotteryDrawBase.limitWay==10){
                        $("#limitWay1").prop("checked", true);
                        $("#limitWay1").attr("disabled", "disabled");
                        $("#limitWay2").attr("disabled", "disabled");
                        $("#fixeds").attr("disabled", "disabled");
                        $("#fixed").css({
                            display: "inline"
                        });
                        $("#fixeds").val(data.data.lotteryDrawBase.limitNum)
                    }else {
                        $("#limitWay2").prop("checked", true);
                        $("#limitWay1").attr("disabled", "disabled");
                        $("#limitWay2").attr("disabled", "disabled");
                        $("#cycles").attr("disabled", "disabled");
                        $("#cycle").css({
                            display: "inline"
                        });
                        $("#cycles").val(data.data.lotteryDrawBase.limitNum)
                    }

                    if(data.data.lotteryDrawBase.virtualNameDisplay==10){
                        $("#virtualNameDisplay").prop("checked", true);
                    }

                    //奖品设置渲染表格
                    prizeListss=data.data.prizeList
                    var prizeList=data.data.prizeList
                    var listHtml=''
                    var jnamne=""
                    for(var i=0; i<prizeList.length; i++){
                        if(prizeList[i].prizeTag==20||prizeList[i].prizeTag==30){
                            jnamne='<span class="Prizenames"  id="Prizename'+prizeList[i].orderNumber+'">'+prizeList[i].prizeName+'</span><br><span id="ids'+prizeList[i].orderNumber+'">ID:<span class="youhuij" id="idcode'+prizeList[i].orderNumber+'">'+prizeList[i].couponSendCode+'</span></span><span style="display: none" class="amounts1" id="amounts'+prizeList[i].orderNumber+'">'+prizeList[i].couponAmount+'</span><span style="display: none" class="" id="sendTotalNums'+prizeList[i].orderNumber+'"></span><span style="display: none" class="useConditions1" id="useConditions'+prizeList[i].orderNumber+'">'+prizeList[i].couponUseCondition+'</span><span style="display: none" class="prizeId1">'+prizeList[i].prizeId+'</span>'
                        }else {
                            jnamne='<span class="Prizenames"  id="Prizename'+prizeList[i].orderNumber+'">'+prizeList[i].prizeName+'</span><br><span id="ids'+prizeList[i].orderNumber+'" style="display: none">ID:<span class="youhuij" id="idcode'+prizeList[i].orderNumber+'"></span></span><span style="display: none" class="amounts1" id="amounts'+prizeList[i].orderNumber+'">'+prizeList[i].couponAmount+'</span><span style="display: none" class="" id="sendTotalNums'+prizeList[i].orderNumber+'"></span><span style="display: none" class="useConditions1" id="useConditions'+prizeList[i].orderNumber+'">'+prizeList[i].couponUseCondition+'</span><span style="display: none" class="prizeId1">'+prizeList[i].prizeId+'</span>'
                        }
                        listHtml+=''
                            +'<tr id="productList">'
                            +'<td class="nus">'+prizeList[i].orderNumber+'</td>'
                            +'<td class="rfqg_td1">'
                            +'<input type="button" id="setups'+prizeList[i].orderNumber+'" style="display: none" class="btn  radius size-S"  onclick="setup('+prizeList[i].orderNumber+')" value="设置"><span>'+jnamne+'</span>'
                            +'</td>'
                            +'<td class="rfqg_td2">'
                            +'<input type="text" style="width: 107px;" oninput="checkMaxIut(this)" id="nameshow'+prizeList[i].orderNumber+'" name="brandne2"  class="input-text nameshows" value='+prizeList[i].prizeDisplayName+'  autocomplete="off">'
                            +'</td>'
                            +'<td class="rfqg_td3">'
                            +'<input type="text" style="width: 107px;" id="number'+prizeList[i].orderNumber+'"   class="input-text numbers" onchange="numbers('+prizeList[i].orderNumber+',this)"  name="brandne3"    autocomplete="off" oninput=\'this.value=this.value.replace(/^[0]+[0-9]*$/gi,"")\' onkeyup="this.value=this.value.replace(/\\D/g,\'\')" \n' + 'onafterpaste="this.value=this.value.replace(/\\D/g,\'\')" maxlength="9" value='+prizeList[i].count+'>'
                            +'</td>'
                            +'<td class="rfqg_td4">'
                            +'<span id="probability'+prizeList[i].orderNumber+'">'+prizeList[i].winProbability+'</span>'
                            +'</td>'
                            +'<td class="rfqg_td5">'
                            +'<a id="edit'+prizeList[i].orderNumber+'" style="color: #0f9ae0" onclick="edit('+prizeList[i].orderNumber+')">编辑</a>'
                            +'</td>'
                            +'</tr>'
                        $('#shunlist').html(listHtml)

                    }


                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        });
    })

}

var llmap=new Map();
//渲染奖品名称列
function xuanran() {

    var vals=sessionStorage.getItem("setupSerials")//序号
    var codes=sessionStorage.getItem("codes")//优惠券发券编码
    $("#edit"+vals).attr("style","color: #0f9ae0")

    //赋值满减劵，运费劵ID
console.log(sessionStorage.getItem("amount"))
    $("#amounts"+vals).text(sessionStorage.getItem("amount"))//优惠劵面额
    $("#sendTotalNums"+vals).text(sessionStorage.getItem("sendTotalNum"))//优惠劵面额
    $("#useConditions"+vals).text(sessionStorage.getItem("useCondition"))//使用条件


    //输入的数量不能大于优惠劵数量
  if(sessionStorage.getItem("jpnid")==20||sessionStorage.getItem("jpnid")==30){
      console.log($("#number"+vals).val())
      console.log(sessionStorage.getItem("sendTotalNum"))
      if(Number($("#number"+vals).val())>Number(sessionStorage.getItem("sendTotalNum"))){
          layer.msg("输入的数量不能大于优惠劵数量，请重新输入", {icon: 5, time: 1000});
          $("#number"+vals).val("")
          $("#probability"+vals).html("")
          return false;
      }
  }



    if(sessionStorage.getItem("jpnid")==20||sessionStorage.getItem("jpnid")==30){
        var couponCode = sessionStorage.getItem("codes");
        console.log("key为：" + couponCode);
        var a = 0;
        for (var key of llmap.keys()){
            console.log("key:"+key)
            if (key == couponCode){
                console.log("key为：" + couponCode);
                a = 1;
                break;
            }
        }
        if (a == 1){
            console.log(llmap)
            console.log(llmap.get(couponCode))
            if(vals!=llmap.get(couponCode)){
                layer.msg("此优惠券主题编码已存在", {icon: 5, time: 1000})
            }else {
                $("#setups"+vals).hide();//设置按钮隐藏
                $("#Prizename"+vals).text(sessionStorage.getItem("jpnames"));//赋值奖品名称
                $("#Prizename"+vals).val(sessionStorage.getItem("jpnid"));//赋值奖品id
                if(sessionStorage.getItem("jpnid")=="20"||sessionStorage.getItem("jpnid")=="30"){
                    $("#ids"+vals).css({
                        display: "inline"
                    });
                    $("#idcode"+vals).text(codes);
                }else {
                    $("#ids"+vals).css({
                        display: "none"
                    });
                }
                //奖品展示名称，数量可编辑
                $("#nameshow"+vals).removeAttr("disabled");
                $("#number"+vals).removeAttr("disabled");
            }
        } else {
            $("#setups"+vals).hide();//设置按钮隐藏
            $("#Prizename"+vals).text(sessionStorage.getItem("jpnames"));//赋值奖品名称
            $("#Prizename"+vals).val(sessionStorage.getItem("jpnid"));//赋值奖品id
            if(sessionStorage.getItem("jpnid")=="20"||sessionStorage.getItem("jpnid")=="30"){
                $("#ids"+vals).css({
                    display: "inline"
                });
                $("#idcode"+vals).text(codes);
            }else {
                $("#ids"+vals).css({
                    display: "none"
                });
            }
            //奖品展示名称，数量可编辑
            $("#nameshow"+vals).removeAttr("disabled");
            $("#number"+vals).removeAttr("disabled");
            llmap.set(sessionStorage.getItem("codes"),vals);
        }


    }else {
        //用这个val得到key，删除key
        var keyw = '';
        for (var key of llmap.keys()){
            if (llmap.get(key) == vals){
                keyw = key;
            }
        }
        llmap.delete(keyw)
        $("#setups"+vals).hide();//设置按钮隐藏
        $("#Prizename"+vals).text(sessionStorage.getItem("jpnames"));//赋值奖品名称
        $("#Prizename"+vals).val(sessionStorage.getItem("jpnid"));//赋值奖品id
        if(sessionStorage.getItem("jpnid")=="20"||sessionStorage.getItem("jpnid")=="30"){
            $("#ids"+vals).css({
                display: "inline"
            });
            $("#idcode"+vals).text(codes);
        }else {
            $("#ids"+vals).css({
                display: "none"
            });
        }
        //奖品展示名称，数量可编辑
        $("#nameshow"+vals).removeAttr("disabled");
        $("#number"+vals).removeAttr("disabled");
    }

}
//编辑
function edit(val) {


    if(gamestares==0) {
        if($("#Prizename"+val).val()!=""){
            sessionStorage.setItem("xuan",'456')
            sessionStorage.setItem("Serials",val)
            sessionStorage.setItem("zhi",$("#Prizename"+val).val())
            sessionStorage.setItem("codeids",$("#idcode"+val).text())
            sessionStorage.setItem("amountsall",$("#amounts"+val).text())
            layer_show("编辑奖品", "../promotion/setUp.html", "600", "300");
        }

    }else {
        console.log($("#idcode"+val).text())
        sessionStorage.setItem("xuan",'456')
        sessionStorage.setItem("Serials",val)
        if($("#Prizename"+val).html()=='谢谢参与'){
            sessionStorage.setItem("zhi",10)
        }else  if($("#Prizename"+val).html()=='满减劵'){
            sessionStorage.setItem("zhi",20)
        }else  if($("#Prizename"+val).html()=='运费劵'){
            sessionStorage.setItem("zhi",30)
        }else  if($("#Prizename"+val).html()=='手机'){
            sessionStorage.setItem("zhi",40)
        }else  if($("#Prizename"+val).html()=='平板电脑'){
            sessionStorage.setItem("zhi",50)
        }else  if($("#Prizename"+val).html()=='购物卡'){
            sessionStorage.setItem("zhi",60)
        }else  if($("#Prizename"+val).html()=='赫力斯工具'){
            sessionStorage.setItem("zhi",70)
        }else  if($("#Prizename"+val).html()=='水杯'){
            sessionStorage.setItem("zhi",80)
        }

        sessionStorage.setItem("codeids",$("#idcode"+val).text())
        layer_show("编辑奖品", "../promotion/setUp.html", "600", "300");
    }

}
//计算获奖概率
var rejectSomeArray = {};
function numbers(val,el) {
    //计算总数量
    if(gamestares==0) {
        //小游戏创建
        console.log($("#number"+val).val())
        console.log()
        if($("#Prizename"+val).text()=="满减劵"||$("#Prizename"+val).text()=="运费劵") {
            if ($("#sendTotalNums" + val).text() != "") {
                if (Number($("#number" + val).val()) > Number($("#sendTotalNums" + val).text())) {
                    layer.msg("输入的数量不能大于优惠劵数量，请重新输入", {icon: 5, time: 1000});
                    $("#number" + val).val("")
                    $("#probability" + val).html("")
                    return false;
                }
            }
        }
        var zongjis=0
        rejectSomeArray[val] ={
            "zongshu":$(el).val(),
        }
        for(var key in rejectSomeArray){
            console.log(rejectSomeArray[key])
            zongjis+=Number(rejectSomeArray[key].zongshu)

        }
        console.log(zongjis)
        //渲染单个获奖概率
        var danshu1=  $("#number1").val()/zongjis*100
        if($("#number1").val()!=""){
            $("#probability1").text((danshu1).toFixed(6))
        }else {
            $("#probability1").text("")
        }
        var danshu2=  $("#number2").val()/zongjis*100
        if($("#number2").val()!=""){
            $("#probability2").text((danshu2).toFixed(6))
        }else {
            $("#probability2").text("")
        }
        var danshu3=  $("#number3").val()/zongjis*100
        if($("#number3").val()!=""){
            $("#probability3").text((danshu3).toFixed(6))
        }else {
            $("#probability3").text("")
        }
        var danshu4=  $("#number4").val()/zongjis*100
        if($("#number4").val()!=""){
            $("#probability4").text((danshu4).toFixed(6))
        }else {
            $("#probability4").text("")
        }
        var danshu5=  $("#number5").val()/zongjis*100
        if($("#number5").val()!=""){
            $("#probability5").text((danshu5).toFixed(6))
        }else {
            $("#probability5").text("")
        }
        var danshu6=  $("#number6").val()/zongjis*100
        if($("#number6").val()!=""){
            $("#probability6").text((danshu6).toFixed(6))
        }else {
            $("#probability6").text("")
        }
        var danshu7=  $("#number7").val()/zongjis*100
        if($("#number7").val()!=""){
            $("#probability7").text((danshu7).toFixed(6))
        }else {
            $("#probability7").text("")
        }
        var danshu8=  $("#number8").val()/zongjis*100
        if($("#number8").val()!=""){
            $("#probability8").text((danshu8).toFixed(6))
        }else {
            $("#probability8").text("")
        }

    }else {
        //小游戏编辑
        console.log($("#number"+val).val())
        console.log($("#sendTotalNums"+val).text())
        console.log($("#Prizename"+val).text())
        if($("#Prizename"+val).text()=="满减劵"||$("#Prizename"+val).text()=="运费劵") {
            if ($("#sendTotalNums" + val).text() != "") {
                if (Number($("#number" + val).val()) > Number($("#sendTotalNums" + val).text())) {
                    layer.msg("输入的数量不能大于优惠劵数量，请重新输入", {icon: 5, time: 1000});
                    $("#number" + val).val("")
                    $("#probability" + val).html("")
                    return false;
                }
            }
        }
    console.log($("#Prizename"+val).text())
        //判断输入的数量不能大于优惠劵数量
        var topicType=""
        if($("#Prizename"+val).text()=="运费劵"){
            topicType=20
        }else {
            topicType=10
        }
        $.ajax({
            url:'https://'+ window.location.host +'/api/admin/acoupon/queryLottery/listCouponSendBySendCode',
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "topicType":topicType,
                "sendCouponCode":$("#idcode"+val).text()
            }),
            success: function (data) {
                if(data.errorCode=="0"){
                    var jsonObj =data.data;
                    for (var  i= 0; i < jsonObj.length; i++) {

                        var sendTotalNumsd=jsonObj[i].sendTotalNum
                        console.log(sendTotalNumsd)
                        if($("#Prizename"+val).text()=="满减劵"||$("#Prizename"+val).text()=="运费劵") {
                            if (Number($("#number" + val).val()) > Number(sendTotalNumsd)) {
                                layer.msg("输入的数量不能大于优惠劵数量，请重新输入", {icon: 5, time: 1000});
                                $("#number" + val).val("")
                                $("#probability" + val).html("")
                                return false;
                            }

                        }
                    }

                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })
        var zongjis=0

        var objArrs=[]
        console.log($(".numbers"))
        let numbers= $(".numbers")//奖品数量
        for (let i=0;i<numbers.length;i++) {
            objArrs.push({
                "count": $(numbers[i]).val(),

            });
        }
        $.each(objArrs,function(k,v){
            console.log(v.count)
            zongjis+=Number(v.count)
        })
        console.log(zongjis)
        //渲染单个获奖概率
        var danshu1=  $("#number1").val()/zongjis*100
        if($("#number1").val()!=""){
            $("#probability1").text((danshu1).toFixed(6))
        }else {
            $("#probability1").text("")
        }
        var danshu2=  $("#number2").val()/zongjis*100
        if($("#number2").val()!=""){
            $("#probability2").text((danshu2).toFixed(6))
        }else {
            $("#probability2").text("")
        }
        var danshu3=  $("#number3").val()/zongjis*100
        if($("#number3").val()!=""){
            $("#probability3").text((danshu3).toFixed(6))
        }else {
            $("#probability3").text("")
        }
        var danshu4=  $("#number4").val()/zongjis*100
        if($("#number4").val()!=""){
            $("#probability4").text((danshu4).toFixed(6))
        }else {
            $("#probability4").text("")
        }
        var danshu5=  $("#number5").val()/zongjis*100
        if($("#number5").val()!=""){
            $("#probability5").text((danshu5).toFixed(6))
        }else {
            $("#probability5").text("")
        }
        var danshu6=  $("#number6").val()/zongjis*100
        if($("#number6").val()!=""){
            $("#probability6").text((danshu6).toFixed(6))
        }else {
            $("#probability6").text("")
        }
        var danshu7=  $("#number7").val()/zongjis*100
        if($("#number7").val()!=""){
            $("#probability7").text((danshu7).toFixed(6))
        }else {
            $("#probability7").text("")
        }
        var danshu8=  $("#number8").val()/zongjis*100
        if($("#number8").val()!=""){
            $("#probability8").text((danshu8).toFixed(6))
        }else {
            $("#probability8").text("")
        }

    }


}
//参加要求展示
function integral(val) {
    if(gamestares==0){
        //小游戏创建
        if(val==1){
            $("#integrals").val("")
            $("#integral").css({
                display: "inline"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#orderjin").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").val("")
            $("#fixeds").removeAttr("disabled")
            $("#cycles").val("")
            $("#cycles").removeAttr("disabled")
        }else if(val==2){
            $("#ordershus").val("")
            $("#ordershu").css({
                display: "inline"
            });
            $("#integral").css({
                display: "none"
            });
            $("#orderjin").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").val("10000")
            $("#fixeds").attr("disabled", "disabled")
            $("#cycles").val("10000")
            $("#cycles").attr("disabled", "disabled")
        }else if(val==3){
            $("#orderjins").val("")
            $("#orderjin").css({
                display: "inline"
            });
            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").val("10000")
            $("#fixeds").attr("disabled", "disabled")
            $("#cycles").val("10000")
            $("#cycles").attr("disabled", "disabled")
        }else if(val==4){
            $("#orderjin").css({
                display: "none"
            });
            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").val("")
            $("#fixeds").removeAttr("disabled")
            $("#cycles").val("")
            $("#cycles").removeAttr("disabled")
        }else if(val==5){
            $("#orderjin").css({
                display: "none"
            });
            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").val("")
            $("#fixeds").removeAttr("disabled")
            $("#cycles").val("")
            $("#cycles").removeAttr("disabled")
        }
        else if(val==6){
            $("#singleStrokes").val("")

            $("#singleStroke").css({
                display: "inline"
            });

            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#orderjin").css({
                display: "none"
            });
            $("#fixeds").val("")
            $("#fixeds").removeAttr("disabled")
            $("#cycles").val("")
            $("#cycles").removeAttr("disabled")
        }

    }else {
        //小游戏编辑
        if(val==1){
            if(getLotteryDrawDetail.joinRequire==30){
                $("#integrals").val(getLotteryDrawDetail.joinConsume)
                $("#integral").css({
                    display: "inline"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }else {
                $("#integrals").val("")
                $("#integral").css({
                    display: "inline"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }
            $("#fixeds").removeAttr("disabled")
            $("#cycles").removeAttr("disabled")
        }else if(val==2){
            if(getLotteryDrawDetail.joinRequire==40){
                $("#ordershus").val(getLotteryDrawDetail.joinConsume)
                $("#ordershu").css({
                    display: "inline"
                });
                $("#integral").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }else {
                $("#ordershus").val("")
                $("#ordershu").css({
                    display: "inline"
                });
                $("#integral").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }
            $("#fixeds").val("10000")
            $("#fixeds").attr("disabled", "disabled")
            $("#cycles").val("10000")
            $("#cycles").attr("disabled", "disabled")
        }else if(val==3){
            if(getLotteryDrawDetail.joinRequire==50){
                $("#orderjins").val(getLotteryDrawDetail.joinConsume)
                $("#orderjin").css({
                    display: "inline"
                });
                $("#integral").css({
                    display: "none"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }else {
                $("#orderjins").val("")
                $("#orderjin").css({
                    display: "inline"
                });
                $("#integral").css({
                    display: "none"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#singleStroke").css({
                    display: "none"
                });
            }
            $("#fixeds").val("10000")
            $("#fixeds").attr("disabled", "disabled")
            $("#cycles").val("10000")
            $("#cycles").attr("disabled", "disabled")
        }else if(val==4){
            $("#orderjin").css({
                display: "none"
            });
            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").removeAttr("disabled")
            $("#cycles").removeAttr("disabled")
        }else if(val==5){
            $("#orderjin").css({
                display: "none"
            });
            $("#integral").css({
                display: "none"
            });
            $("#ordershu").css({
                display: "none"
            });
            $("#singleStroke").css({
                display: "none"
            });
            $("#fixeds").removeAttr("disabled")
            $("#cycles").removeAttr("disabled")
        } if(val==6){
            if(getLotteryDrawDetail.joinRequire==60){
                $("#singleStrokes").val(getLotteryDrawDetail.joinConsume)
                $("#singleStroke").css({
                    display: "inline"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#integral").css({
                    display: "none"
                });
            }else {
                $("#singleStrokes").val("")
                $("#singleStroke").css({
                    display: "inline"
                });
                $("#ordershu").css({
                    display: "none"
                });
                $("#orderjin").css({
                    display: "none"
                });
                $("#integral").css({
                    display: "none"
                });
            }
            $("#fixeds").removeAttr("disabled")
            $("#cycles").removeAttr("disabled")
        }

    }


}
//抽奖方式展示
function luckdraw(val) {
    if(gamestares==0){
        //小游戏创建
        if(val==1){
            $("#fixeds").val("")
            $("#fixed").css({
                display: "inline"
            });
            $("#cycle").css({
                display: "none"
            });
            if($('input:radio[name="joinRequire"]:checked').val()==40||$('input:radio[name="joinRequire"]:checked').val()==50){
                $("#fixeds").val("10000")
                $("#fixeds").attr("disabled", "disabled")
            }else {
                $("#fixeds").val("")
                $("#fixeds").removeAttr("disabled")
            }
        }else {
            $("#cycles").val("")
            $("#fixed").css({
                display: "none"
            });
            $("#cycle").css({
                display: "inline"
            });
            if($('input:radio[name="joinRequire"]:checked').val()==40||$('input:radio[name="joinRequire"]:checked').val()==50){
                $("#cycles").val("10000")
                $("#cycles").attr("disabled", "disabled")
            }else {
                $("#cycles").val("")
                $("#cycles").removeAttr("disabled")
            }
        }
    }else {
        //小游戏编辑
        if(val==1){
            if(getLotteryDrawDetail.limitWay==10){
                $("#fixeds").val(getLotteryDrawDetail.limitNum)
                $("#fixed").css({
                    display: "inline"
                });
                $("#cycle").css({
                    display: "none"
                });
            }else {
                $("#fixeds").val("")
                $("#fixed").css({
                    display: "inline"
                });
                $("#cycle").css({
                    display: "none"
                });
            }
            if($('input:radio[name="joinRequire"]:checked').val()==40||$('input:radio[name="joinRequire"]:checked').val()==50){
                $("#fixeds").val("10000")
                $("#fixeds").attr("disabled", "disabled")
            }else {
                $("#fixeds").val("")
                $("#fixeds").removeAttr("disabled")
            }
        }else {
            if(getLotteryDrawDetail.limitWay==20){
                $("#cycles").val(getLotteryDrawDetail.limitNum)
                $("#fixed").css({
                    display: "none"
                });
                $("#cycle").css({
                    display: "inline"
                });
            }else {
                $("#cycles").val("")
                $("#fixed").css({
                    display: "none"
                });
                $("#cycle").css({
                    display: "inline"
                });
            }
            if($('input:radio[name="joinRequire"]:checked').val()==40||$('input:radio[name="joinRequire"]:checked').val()==50){
                $("#cycles").val("10000")
                $("#cycles").attr("disabled", "disabled")
            }else {
                $("#cycles").val("")
                $("#cycles").removeAttr("disabled")
            }
        }
    }



}
var applPaidType ='';
$(".paidType").change(function() {
    applPaidType ='';
    var groupCheckbox =  $(".paidType");
    for(var i=0;i<groupCheckbox.length;i++){
        if(groupCheckbox[i].checked){
            var val =groupCheckbox[i].value;
            if(i==groupCheckbox.length-1){
                applPaidType += val ;
            }else{
                applPaidType += val +',';
            }
        }
        if(groupCheckbox[i].checked==false){
            document.getElementById("applPaidType0").checked = false;
        }
    }

});

var count = 0;//默认 没有
function check_pay(){
    if(count==0){
        document.getElementById("applPaidType0").checked=true;
        $(".paidType").prop("checked",true);
        count = 1;
        applPaidType = document.getElementById("applPaidType0").value;
        console.log(applPaidType);
    }else if(count==1){
        document.getElementById("applPaidType0").checked=false;
        $(".paidType").prop("checked",false);
        count = 0;
        applPaidType = '';
    }
}
/*
$("#addcreation") .Validform({
    submitHandler:function(){
   }
})*/
var isIng = false;
function checkForm() {

    var joinConsumes=""
    var limitNums=""
    applPaidType = '';
    if(document.getElementById("applPaidType0").checked){
        applPaidType = $('#applPaidType0').val();
    }else{
        var groupCheckbox =  $(".paidType");
        for(i=0;i<groupCheckbox.length;i++){
            if(groupCheckbox[i].checked){
                var val =groupCheckbox[i].value;
                if(i==groupCheckbox.length-1){
                    applPaidType += val ;
                }else{
                    applPaidType += val +',';
                }
            }
        }
    }
    if($('input:radio[name="joinRequire"]:checked').val()==10){
        joinConsumes=0
    }else if($('input:radio[name="joinRequire"]:checked').val()==20){
        joinConsumes=0
    }else if($('input:radio[name="joinRequire"]:checked').val()==30){
        joinConsumes=$("#integrals").val()
    }else if($('input:radio[name="joinRequire"]:checked').val()==40){
        joinConsumes= $("#ordershus").val()
    }else if($('input:radio[name="joinRequire"]:checked').val()==50){
        joinConsumes= $("#orderjins").val()
    }else if($('input:radio[name="joinRequire"]:checked').val()==60){
        joinConsumes= $("#singleStrokes").val()
    }
    if($('input:radio[name="platforiiim"]:checked').val()==10){
        limitNums= $("#fixeds").val()
    }else if($('input:radio[name="platforiiim"]:checked').val()==20){
        limitNums=   $("#cycles").val()
    }
    ue.ready(function() {
        text = ue.getContent();
    });
    if(gamestares==0) {
        var lotteryDrawBase = {
            "lotteryAfterName": $("#lotteryAfterName").val(),
            "lotteryBeforeName": $("#lotteryBeforeName").val(),
            "startTime": $("#logmin").val(),
            "endTime": $("#logmax").val(),
            "platform": 10,
            "customerType": "20,30",
            "source": applPaidType,
            "joinRequire": $('input:radio[name="joinRequire"]:checked').val(),
            "joinConsume": joinConsumes,
            "limitWay": $('input:radio[name="platforiiim"]:checked').val(),
            "limitNum": limitNums,
            "virtualNameDisplay": $('input:checkbox[name="virtualNameDisplay"]:checked').val(),
            "rule": text,
            "createName": JSON.parse(web.readCookie("loginData")).user.name
        }
    }else {
        var lotteryDrawBase = {
            "lotteryAfterName": $("#lotteryAfterName").val(),
            "lotteryBeforeName": $("#lotteryBeforeName").val(),
            "startTime": $("#logmin").val(),
            "endTime": $("#logmax").val(),
            "platform": 10,
            "customerType": "20,30",
            "source": applPaidType,
            "joinRequire": $('input:radio[name="joinRequire"]:checked').val(),
            "joinConsume": joinConsumes,
            "limitWay": $('input:radio[name="platforiiim"]:checked').val(),
            "limitNum": limitNums,
            "virtualNameDisplay": $('input:checkbox[name="virtualNameDisplay"]:checked').val(),
            "rule": text,
            "createName": JSON.parse(web.readCookie("loginData")).user.name,
            "lotteryId":lotteryIdfd,
            "status":getLotteryDrawDetail.status
        }
    }
    var objArr=[];
    let brandslength = $("input[name='brandne3']")
    let brandslength2 = $("input[name='brandne2']")
    let Prizenames= $(".Prizenames")//奖品名称
    let nameshows= $(".nameshows")//奖品展示名称
    let numbers= $(".numbers")//奖品数量
    let idcode=$(".youhuij")//编码
    let nus= $(".nus")//序号
    let amounts=$(".amounts1")//优惠劵面额
    let useConditions=$(".useConditions1")//使用条件
    var prizeId1s=$(".prizeId1")
    console.log(brandslength)
    for (let i=0;i<brandslength.length;i++) {

        console.log()
        if($("#lotteryAfterName").val()!=""&&$("#lotteryBeforeName").val()!=""&&$("#logmin").val()!=""&&$("#logmax").val()!=""&&$('input:radio[name="joinRequire"]:checked').val()!=undefined &&$('input:radio[name="platforiiim"]:checked').val()!=undefined ){


            if(text==""){
                layer.msg("请填写活动规则", {icon: 5, time: 1000});
                isIng = false;
                return false;
            }
            let shu = $(brandslength[i]).val();
            let name = $(brandslength2[i]).val();
            if(shu==""||name==""){
                layer.msg("请选择奖品名称，并配置8个奖品", {icon: 5, time: 3000});
                isIng = false;
                return false;
            }
        }else {
            return false;
        }

        if(gamestares==0) {
            console.log($(amounts[i]).html())
            //创建时
            if($(Prizenames[i]).html()=='满减劵'||$(Prizenames[i]).html()=='运费劵'){
                objArr.push({
                    "prizeName": $(Prizenames[i]).html(),
                    "prizeDisplayName": $(nameshows[i]).val(),
                    "count":$(numbers[i]).val(),
                    "orderNumber": $(nus[i]).html(),
                    "prizeType":10,
                    "prizeTag":$(Prizenames[i]).val(),
                    "couponSendCode":$(idcode[i]).html(),
                    "couponAmount":$(amounts[i]).html(),
                    "couponUseCondition":$(useConditions[i]).html(),
                });
            }else {
                objArr.push({
                    "prizeName": $(Prizenames[i]).html(),
                    "prizeDisplayName": $(nameshows[i]).val(),
                    "count":$(numbers[i]).val(),
                    "orderNumber": $(nus[i]).html(),
                    "prizeType":20,
                    "prizeTag":$(Prizenames[i]).val(),
                    "couponAmount":$(amounts[i]).html(),
                    "couponUseCondition":$(useConditions[i]).html(),
                });
            }
        }else {
            var prizeTags=""
            if($(Prizenames[i]).html()=='谢谢参与'){
                prizeTags="10"
            }else  if($(Prizenames[i]).html()=='满减劵'){
                prizeTags="20"
            }else  if($(Prizenames[i]).html()=='运费劵'){
                prizeTags="30"
            }else  if($(Prizenames[i]).html()=='手机'){
                prizeTags="40"
            }else  if($(Prizenames[i]).html()=='平板电脑'){
                prizeTags="50"
            }else  if($(Prizenames[i]).html()=='购物卡'){
                prizeTags="60"
            }else  if($(Prizenames[i]).html()=='赫力斯工具'){
                prizeTags="70"
            }else  if($(Prizenames[i]).html()=='水杯'){
                prizeTags="80"
            }
            console.log($(amounts[i]).html())
            //修改时
            if($(Prizenames[i]).html()=='满减劵'||$(Prizenames[i]).html()=='运费劵'){
                objArr.push({
                    "prizeName": $(Prizenames[i]).html(),
                    "prizeDisplayName": $(nameshows[i]).val(),
                    "count":$(numbers[i]).val(),
                    "orderNumber": $(nus[i]).html(),
                    "prizeType":10,
                    "prizeTag":prizeTags,
                    "couponSendCode":$(idcode[i]).html(),
                    "couponAmount":$(amounts[i]).html(),
                    "couponUseCondition":$(useConditions[i]).html(),
                    "prizeId":$(prizeId1s[i]).html(),
                });
            }else {
                objArr.push({
                    "prizeName": $(Prizenames[i]).html(),
                    "prizeDisplayName": $(nameshows[i]).val(),
                    "count":$(numbers[i]).val(),
                    "orderNumber": $(nus[i]).html(),
                    "prizeType":20,
                    "prizeTag":prizeTags,
                    "couponAmount":$(amounts[i]).html(),
                    "couponUseCondition":$(useConditions[i]).html(),
                    "prizeId":$(prizeId1s[i]).html(),
                });
            }
        }

    }
    var urls=""
    if(gamestares==0){
        urls='https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/createLotteryDraw'
    }else {
        urls='https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/updateLotteryDrawDetail'
    }

        if(isIng){
            layer.msg('请求已提交，请勿重复点击！');
            return false;
        }
        isIng = true;

    $.ajax({
        url:urls,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "lotteryDrawBase":lotteryDrawBase,
            "prizeList":objArr,
        }),
        success: function (data) {
            if(data.errorCode==0){
                layer.msg('创建成功', {icon: 6, time: 1000});
                setTimeout( function () {
                    parent.layer.closeAll();
                },700);
            }else {
                isIng = false;
                layer.msg(data.message, {icon: 5, time: 1000});
            }

        },
        error: function () {
            isIng = false;
            $.Huimodalalert('失败！',2000);
        }
    })
}
//限制字符
var len
var Preser
var common=20//要限制输入的字数
function checkMaxIut(me) {
    var text=$(me).val()
    strlen(text)
    if(len>common){
        $(me).val(Preser)
    }else {
        Preser=$(me).val()
    }
}
function strlen(str){
    len = 0;
    for (var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            len++;
        } else {
            len+=2;
        }
    }
    $('#textSpan').text((len>20)?20:len)
    return len;
}